package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.ControlFieldVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ControlField;
import com.ruoyi.system.service.IControlFieldService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 控件字段Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/system/control/field")
public class ControlFieldController extends BaseController
{
    @Autowired
    private IControlFieldService controlFieldService;

    /**
     * 查询控件字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(ControlField controlField)
    {
        startPage();
        List<ControlField> list = controlFieldService.selectControlFieldList(controlField);
        return getDataTable(list);
    }

    /**
     * 查询控件字段列表Vo
     */
    @GetMapping("/voList")
    public TableDataInfo voList(ControlField controlField)
    {
        startPage();
        List<ControlFieldVO> controlFieldVOS = controlFieldService.selectControlFieldVOList(controlField);
        return getDataTable(controlFieldVOS);
    }


    /**
     * 导出控件字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:field:export')")
    @Log(title = "控件字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ControlField controlField)
    {
        List<ControlField> list = controlFieldService.selectControlFieldList(controlField);
        ExcelUtil<ControlField> util = new ExcelUtil<ControlField>(ControlField.class);
        util.exportExcel(response, list, "控件字段数据");
    }

    /**
     * 获取控件字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:field:query')")
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") Long fieldId)
    {
        return success(controlFieldService.selectControlFieldByFieldId(fieldId));
    }

    /**
     * 新增控件字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:add')")
    @Log(title = "控件字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ControlField controlField)
    {
        return toAjax(controlFieldService.insertControlField(controlField));
    }

    /**
     * 修改控件字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:edit')")
    @Log(title = "控件字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ControlField controlField)
    {
        return toAjax(controlFieldService.updateControlField(controlField));
    }

    /**
     * 删除控件字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:remove')")
    @Log(title = "控件字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable Long[] fieldIds)
    {
        return toAjax(controlFieldService.deleteControlFieldByFieldIds(fieldIds));
    }
}
